package com.iaz.tech.tools.ai.neuron.cell;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.mybatis.logging.LoggerFactory;
import org.slf4j.Logger;

import com.iaz.tech.tools.ai.neuron.ability.INeuronAbility;
import com.iaz.tech.tools.ai.neuron.ability.INeuronCreateCommunicateAbility;
import com.iaz.tech.tools.ai.neuron.ability.INeuronProgramAbility;
import com.iaz.tech.tools.message.IMessageAble;
import com.iaz.tech.tools.property.IPropertyAble;
import com.iaz.tech.tools.property.project.Project;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 组织单元格， 用于日常管理与协调
 * 接收
 * 1） 组织内的神经元的消息
 * 2） 发起工程
 * 3） 协调组织技能
 * 4） 规定学习机经验整理
 */
@EqualsAndHashCode(callSuper=false)
@Data
public class OrganizationCell extends Neuron implements INeuronProgramAbility, INeuronCreateCommunicateAbility{
    /**
     * 日志
     */
	private final static Logger logger = (Logger) LoggerFactory.getLogger(OrganizationCell.class);

    /**
     * 当前工程
     */
    private Project project = null;

    /**
     * 组织内的神经元的消息
     */
    @Override
    public IMessageAble talk(UUID neuronID, IMessageAble message) {
        IMessageAble result = null;
        try {
            // 组织内的神经元的消息
            if (message == null) {
                throw new IllegalArgumentException("message is null");
            }
            // 检查工程是否存在
            if (this.project == null) {
                throw new IllegalArgumentException("project is null");
            }
            

        } catch (Exception e) {
            logger.error("OrganizationCell talk error, neuronID: {}, message: {}", neuronID, message, e);
            return null;
        }
        return result;
    }

    @Override
    public List<IMessageAble> answer(UUID id) {
        List<IMessageAble> result = new ArrayList<>();
        try {

        } catch(Exception e){
            logger.error("OrganizationCell answer error, id: {}", id, e);
            return null;
        }
        return result;
    }
    /**
     * 任务调用用的
     */
    @Override
    public void execute(Object sender) {
        try {
            // 检查工程是否存在
            if (this.project == null) {
                throw new IllegalArgumentException("project is null");
            }
            
        } catch (Exception e) {
            logger.error("OrganizationCell execute error, sender: {}", sender, e);
        }
    }

    @Override
    public long forExecuteTime() {
        return this.getCurrentTime();
    }

    @Override
    public void stop() {
        // TODO Auto-generated method stub
        throw new UnsupportedOperationException("Unimplemented method 'stop'");
    }

    @Override
    public INeuronAbility applyNewCommunication() {
        // TODO Auto-generated method stub
        throw new UnsupportedOperationException("Unimplemented method 'applyNewCommunication'");
    }

    @Override
    public void appendCommunication(INeuronAbility ability) {
        // TODO Auto-generated method stub
        throw new UnsupportedOperationException("Unimplemented method 'appendCommunication'");
    }

    /**
     * 执行组织单元格，
     * 是实现INeuronProgramAbility 的接口
     */
    @Override
    public IPropertyAble executeProgram(IPropertyAble _property) {
        try {
            return _property;
        } catch (Exception e) {
            logger.error("OrganizationCell execute error, property: {}", _property, e);
            return null;
        }
    }

}
